# Copyright (c) Meta Platforms, Inc. and affiliates.

load("@bazel_skylib//lib:shell.bzl", "shell")
load("@fbcode_macros//build_defs:native_rules.bzl", "buck_filegroup", "buck_genrule", "buck_sh_binary")

oncall("data_compression")

buck_filegroup(
    name = "app_srcs",
    srcs = glob(["**/*"]),
)

buck_genrule(
    name = "yarn-build",
    out = "yarn-build.sh",
    cmd = (
        "echo -e {0} > $OUT && chmod +x $OUT"
            .format(shell.quote("\n".join([
            "#!/bin/sh",
            "pushd \\$(hg root)/fbcode/data_compression/experimental/zstrong/tools/visualization_app",
            "yarn build",
            "popd",
        ])))
    ),
)

buck_sh_binary(
    name = "visualization-app-build",
    main = ":yarn-build",
)

buck_genrule(
    name = "yarn-test",
    out = "yarn-test.sh",
    cmd = (
        "echo -e {0} > $OUT && chmod +x $OUT"
            .format(shell.quote("\n".join([
            "#!/bin/sh",
            "cd \\$(dirname \\$0)",
            "cd \\$(hg root)/fbcode/data_compression/experimental/zstrong/tools/visualization_app",
            "yarn install",
            "yarn test:run",
        ])))
    ),
)

# disabled for now. vitest 3.2.4 has a security vulnerability that prevents us from using it.
# vitest 4.0.0 is in beta. This test will be re-enabled when it becomes generally available.
# buck_sh_test(
#     name = "visualization-app-tests",
#     test = ":yarn-test",
# )
